
ITEM.isbase = true
ITEM.class = "base_weapon"
ITEM.label = "Base Weapon"
ITEM.description = "The base weapon item.\nCould be used to make a working weapon..."
ITEM.weight = 1
ITEM.model = "models/Weapons/w_bugbait.mdl"
ITEM.icon = "wintersurvival/icon_bugbait"

//Inventory

function ITEM:onInvSelect(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	
	if not itemtab then
		inv[self.class] = {}
		itemtab = inv[self.class]
		itemtab.lastused = CurTime() - self.cooldown
	end
	
	if SERVER then
		if pl:Alive() and pl:GetActiveWeapon() and pl:GetActiveWeapon().SetWeaponHoldType and not pl:WSIsPigeon() then
			pl:GetActiveWeapon():SetWeaponHoldType(self.holdtype)
		end
		
		local rp = RecipientFilter()
		rp:AddAllPlayers()
		
		umsg.Start("wsWeapon",rp)
			umsg.Entity(pl)
			umsg.String(self.class)
		umsg.End()
	end
end

function ITEM:onInvUnSelect(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	
	if SERVER then
		if pl:Alive() and pl:GetActiveWeapon() and pl:GetActiveWeapon().SetWeaponHoldType and not pl:WSIsPigeon() then
			pl:GetActiveWeapon():SetWeaponHoldType("normal") //Why the hell was this self.holdtype?
		end
		
		local rp = RecipientFilter()
		rp:AddAllPlayers()
		
		umsg.Start("wsWeapon",rp)
			umsg.Entity(pl)
			umsg.String("!none") //Why the hell was this self.class?
		umsg.End()
	end
end

//Macros

function ITEM:FireAfterCooldown(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	//local itemtab = GM.pldat[pl:UniqueID()][self.class]
	
	//Automatically fire next possible time
	timer.Create("pri_"..self.class,itemtab.lastused+self.cooldown-CurTime()+.001,1,function()
		local GM = gmod.GetGamemode()
		//local itemtab = GM.pldat[pl:UniqueID()][self.class]
		local itemtab,inv = self:getDatTab(pl)
		
		//Check if the item is still equipped
		local equipped = false
		if SERVER then
			equipped = (GM.pldat[pl:UniqueID()].invsel == self.class)
		elseif CLIENT then
			equipped = (GM.invsel.curclass)
		end
		
		
		if equipped then
			self:onPrimary(pl)
		end
	end)
end

function ITEM:FireSecondaryAfterCooldown(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	//local itemtab = GM.pldat[pl:UniqueID()][self.class]
	
	//Automatically fire next possible time
	timer.Create("sec_"..self.class,itemtab.lastused+self.cooldown-CurTime()+.001,1,function()
		local GM = gmod.GetGamemode()
		//local itemtab = GM.pldat[pl:UniqueID()][self.class]
		local itemtab,inv = self:getDatTab(pl)
		
		//Check if the item is still equipped
		local equipped = false
		if SERVER then
			equipped = (GM.pldat[pl:UniqueID()].invsel == self.class)
		elseif CLIENT then
			equipped = (GM.invsel.curclass)
		end
		
		
		if equipped then
			self:onSecondary(pl)
		end
	end)
end

